<template>
	<el-container>
		<el-header>
			<div class="left-panel">
				邮件查阅情况
			</div>
			<div class="right-panel">
			</div>
		</el-header>
		<el-main class="nopadding">
			<scTable ref="table" :apiObj="apiObj" row-key="deptId" @selection-change="selectionChange" hidePagination>
				<el-table-column label="部门名称" prop="deptName" width="200"></el-table-column>
				<el-table-column label="未查看" width="300" align="center">
					<template #default="scope">
						{{ getNotReadUser(scope.row.deptId) }}
					</template>
				</el-table-column>
				<el-table-column label="已查看" width="300" align="center">
					<template #default="scope">
						{{ getReadUser(scope.row.deptId) }}
					</template>
				</el-table-column>
				<el-table-column label="已删除" width="300" align="center">
					<template #default="scope">
						{{ getDelUser(scope.row.deptId) }}
					</template>
				</el-table-column>
			</scTable>
		</el-main>
	</el-container>


</template>

<script>

export default {
	name: 'News Status',
	components: {},
	data() {
		return {
			apiObj: this.$API.system.unitDept.list,
			selection: [],
			userList: [],
			bodyId: this.$route.query.bodyId
		}
	},
	mounted() {
		this.getNewsStatus();
	},
	methods: {
		async getNewsStatus() {
			var res = await this.$API.email.getEmailReadStatus.get({bodyId: this.bodyId});
			if (res.code == 200) {
				this.userList = res.data;
			} else {
				this.$alert(res.message, "提示", {type: 'error'})
			}
		},
		//表格选择后回调事件
		selectionChange(selection) {
			this.selection = selection;
		},
		getReadUser(deptId) {
			let resArr = [];
			for (var i = 0; i < this.userList.length; i++) {
				if (this.userList[i].deptId == deptId && this.userList[i].isRead == 'true') {
					resArr.push(this.userList[i].userName);
				}
			}
			return resArr.join(",");
		},
		getNotReadUser(deptId) {
			let resArr = [];
			for (var i = 0; i < this.userList.length; i++) {
				if (this.userList[i].deptId == deptId && this.userList[i].isRead == 'false') {
					resArr.push(this.userList[i].userName);
				}
			}
			return resArr.join(",");
		},
		getDelUser(deptId) {
			let resArr = [];
			for (var i = 0; i < this.userList.length; i++) {
				if (this.userList[i].deptId == deptId && this.userList[i].delFlag == '1') {
					resArr.push(this.userList[i].userName);
				}
			}
			return resArr.join(",");
		}
	}
}
</script>

<style>
</style>
